package com.hocmai.user.toprank;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.megastudyletsthi.R;

public class UserTopRankAdapter extends BaseAdapter {

	private Context myContext;
	private List<UserTopRankObject> listUserTopRankObjects;

	public UserTopRankAdapter(Context context, List<UserTopRankObject> list) {
		myContext = context;
		listUserTopRankObjects = list;

	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listUserTopRankObjects.size();
	}

	@Override
	public Object getItem(int pos) {
		// TODO Auto-generated method stub
		return listUserTopRankObjects.get(pos);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		// get selected entry
		UserTopRankObject entry = listUserTopRankObjects.get(position);
		// inflating list view layout if null
		if (convertView == null) {
			LayoutInflater inflater = LayoutInflater.from(myContext);
			convertView = inflater.inflate(R.layout.list_top_user, null);
		}

		// set avatar
		ImageView iViewAvatar = (ImageView) convertView
				.findViewById(R.id.avatar);
		iViewAvatar.setImageBitmap(entry.getAvatar());

		// set badge
		ImageView imageViewBadge = (ImageView) convertView
				.findViewById(R.id.badge);
		imageViewBadge.setImageBitmap(entry.getBadge());

		// set user name
		TextView textViewName = (TextView) convertView
				.findViewById(R.id.user_name);
		textViewName.setText(entry.getUserName());

		// set user scores
		TextView textViewScore = (TextView) convertView
				.findViewById(R.id.user_scores);
		textViewScore.setText(entry.getUserScore());
		return convertView;
	}

}
